package com.epi.one.basic.generic.pair;

import java.util.function.*;

/**
 * @author dxy
 * @version 1.0
 */
public class Pair<T> {
    private T first;
    private T second;

    public Pair() {
    }

    public Pair(T first, T second) {
        this.first = first;
        this.second = second;
    }

    public static <S> Pair<S> makePair(Supplier<S> supplier){
        return new Pair<>(supplier.get(), supplier.get());
    }

    public static <C> Pair<C> makePair(Class<C> clazz){
        try {
            return new Pair<>(clazz.getConstructor().newInstance(),clazz.getConstructor().newInstance());
        } catch (Exception e) {
            return null;
        }
    }

    public T getFirst() {
        return first;
    }

    public T getSecond() {
        return second;
    }

    public void setFirst(T first) {
        this.first = first;
    }

    public void setSecond(T second) {
        this.second = second;
//        Thread.dumpStack();
        StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
        walker.forEach(System.out::println);
    }
}
